/*
 * JHeuristics - The Java Meta-Heuritics Library
 * Copyright (C) 2004-2005, Universidade Federal de Campina Grande. All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.jheuristics.util.conditions;

import org.epanetgrid.otimizacao.ag.ViaveisSelector;
import org.jheuristics.ga.GAStatus;
import org.jheuristics.util.Condition;


/**
 * 
 * @author vinicius
 *
 */
public class MinIndividualsViaveisCondition implements Condition {
	
	private int quantMin;

	/**
	 * TODO
	 *
	 * @param maxGeneration
	 */
	public MinIndividualsViaveisCondition(int quantMin) {
		setQuantMin(quantMin);
	}

	/**
	 * TODO
	 *
	 * @param obj
	 * @return
	 * @see org.jheuristics.util.Condition#check(java.lang.Object)
	 */
	public boolean check(Object obj) {
		if (!(obj instanceof Object[]) || 0 == ((Object[])obj).length || !(((Object[])obj)[0] instanceof GAStatus)) {
			// TODO: ERROR MSG
			throw new IllegalArgumentException();
		}
		GAStatus status =  ((GAStatus)((Object[])obj)[0]);
		int quantViaveis = new ViaveisSelector().select(status.getCurrentPopulation(), 0, null, null).length;
		
		return quantMin > quantViaveis;
	}
	
	/**
	 * TODO
	 *
	 * @param maxGeneration
	 */
	private void setQuantMin(int quantMin) {
		if (0 >= quantMin) {
			// TODO: ERROR MSG
			throw new IllegalArgumentException();
		}
		this.quantMin = quantMin;
	}

}
